
<template>
  <div>
    <div class="p-lr-16 m-t-12">
      <PageList ref="pageListRef" :downOption="downOption" :upOption="upOption" @downCallback="downPullCallback"
        @upCallback="upCallback">
        <div class="p-lr-12 bg-white radius-12 flex-column m-b-12" v-for="(item, index) in list" :key="index"
          @click="goDetail(item, index)">
          <van-cell v-for="item in list" :key="item" :title="item" />
        </div>
      </PageList>
    </div>

  </div>


</template>

<script setup>

import { useTips } from '@/hooks/useTips';

import {
  deepClone,
  isEmpty,
} from '@/util/common';
const {
  showToast,
  showLoading,
  showLoaded,
} = useTips()
const queryParam = ref(getBaseQueryParam())

const router = useRouter()
function getBaseQueryParam() {
  return {}
}
const downOption = ref({
})
const upOption = ref({})
const list = ref([])
const pageListRef = ref()
const downPullCallback = () => {
  list.value = []
  nextTick(() => {
    pageListRef.value.mescrollPageList.resetUpScroll()
  })
}

const upCallback = async ({
  pageNo,
  pageSize
}) => {
  let params = deepClone(queryParam.value) || {}
  Object.assign(params, {
    pageNo,
    pageSize,
  })
  let res = {};
  // showLoading()
  try {
    res = await getOrderList(params)
  } catch (err) {
    console.log('upCallback err', err)
    pageListRef.value.mescrollPageList.upCallbackError()
    return
  }
  console.log('upCallback res', res)
  if (!res?.success) {
    showToast(res?.message || '请求失败')
    pageListRef.value.mescrollPageList.upCallbackError()
    return
  }
  const result = res.result
  const newList = result.records
  const isNextPage = result.pages > pageNo
  if (pageNo === 1) {
    list.value = newList
  } else {
    list.value = list.value.concat(newList)
  }
  pageListRef.value.mescrollPageList.upCallbackSuccess(newList.length, isNextPage)
}


</script>

<style lang="scss" scoped></style>
